<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <div id="app">
      <h2>v-for和v-if不要一起使用</h2>
      <!-- 
        1. 判断的条件和item项无关的时候，可以将v-if放到外层
        2. 判断的条件和item项有关的时候，可以先过滤出一个计算的结果(计算属性)
       -->
      <ul v-if="show">
        <li v-for="item in list" :key="item">{{ item }}</li>
      </ul>

      <ul>
        <!-- <li v-for="item in list2" :key="item" v-if="item % 2">{{ item }}</li> -->
        <li v-for="item in oddList" :key="item">{{ item }}</li>
      </ul>
    </div>

    <script src="./Vue.js"></script>
    <script>
      new Vue({
        el: "#app",
        data: {
          list: ["🍎", "🍌", "🍉"],
          show: false,

          list2: [1, 2, 3, 4, 5, 6, 7],
        },
        computed: {
          oddList() {
            return this.list2.filter((item) => item % 2);
          },
        },
      });
    </script>
  </body>
</html>
